home *** CD-ROM | disk | FTP | other *** search
/ CDV Software Presents (USA) / CDV Software Presents (USA).bin / demo / bk_demo.exe / DATA.PAK / ui / common / commonscript.lua < prev    next >
Encoding:
Text File  |  2002-09-17  |  1.1 KB  |  45 lines

  1. nNumberOfButtons = 0
  2. nActiveButton = 0
  3. bInit = 0
  4.  
  5. --the variable nNumberOfButtons is initilized from GlobalVar
  6. --so that we do not need to write explicit LUA serialize code to save it
  7. --when chapter or campaign screen is loading, the game serialize all GlobalVars
  8. --and script is initializing after all global variables are loaded
  9.  
  10. function ClearState( nControl )
  11.     i = 1000
  12.     while ( i <= 1000 + nNumberOfButtons ) do
  13.         if ( i ~= nControl ) then
  14.             AddMessage( 65536, i, 0 )        --CHANGE_STATE to 0 (clear state)
  15.         end
  16.         i = i + 1
  17.     end
  18. end
  19.  
  20. function LuaProcessMessage( nMessageCode, nFirst, nSecond )
  21.     if ( bInit == 0 ) then
  22.         nNumberOfButtons = InitCommonScript()
  23.         bInit = 1
  24.     end
  25.  
  26.     i = 1000
  27.     while ( i <= 1000 + nNumberOfButtons ) do
  28.         if ( nMessageCode == 536936448 and nFirst == i ) then
  29.             if ( nSecond == 1 ) then
  30.                 nActiveButton = i
  31.                 ClearState( i )
  32.                 return 1
  33.             end
  34.             if ( nActiveButton == i and nSecond == 0 ) then
  35.                 AddMessage( 65536, i, 1 )    --SET_STATE
  36.                 return 1
  37.             end
  38.             return 0
  39.         end
  40.         i = i + 1
  41.     end
  42.  
  43.     return 0
  44. end
  45.